class Solution {
public:
    int numFriendRequests(vector<int>& ages) {
        sort(ages.begin(), ages.end());
        int right = ages.size() - 1;
        int res = 0;
        for(int left = ages.size() - 2; ages[right] >= 15 && right > 0; right--)
        {
            if(left >= right) left = right - 1;
            while(ages[left] > 0.5 * ages[right] + 7 && left >= 0)
            {
                left--;
            }
            int diff = right - left - 1;
            res += diff;
            cout<<left<<endl<<right<<endl<<endl;
            while(right != left + 1 && ages[right - 1] == ages[right])
            {
                right--;
                res += diff;
            }
        }
        return res;
    }
};
